﻿using System;
using System.Reflection;
using System.Linq;
using System.IO;
using Aspose.Zip.Saving;

namespace TL.Test
{
    class Program
    {
        static void Main(string[] args)
        {
            加密();
            解密();
            Console.WriteLine("加解密完成");
            Console.ReadLine();
        }
        public const string Key = @"PExpY2Vuc2U+DQogIDxEYXRhPg0KICAgIDxMaWNlbnNlZFRvPlNoYW5naGFpIEh1ZHVuIEluZm9ybWF0aW9uIFRlY2hub2xvZ3kgQ28uLCBMdGQ8L0xpY2Vuc2VkVG8+DQogICAgPEVtYWlsVG8+MzE3NzAxODA5QHFxLmNvbTwvRW1haWxUbz4NCiAgICA8TGljZW5zZVR5cGU+RGV2ZWxvcGVyIE9FTTwvTGljZW5zZVR5cGU+DQogICAgPExpY2Vuc2VOb3RlPkxpbWl0ZWQgdG8gMSBkZXZlbG9wZXIsIHVubGltaXRlZCBwaHlzaWNhbCBsb2NhdGlvbnM8L0xpY2Vuc2VOb3RlPg0KICAgIDxPcmRlcklEPjE4MDUxNDIwMTExNjwvT3JkZXJJRD4NCiAgICA8VXNlcklEPjI2NjE2NjwvVXNlcklEPg0KICAgIDxPRU0+VGhpcyBpcyBhIHJlZGlzdHJpYnV0YWJsZSBsaWNlbnNlPC9PRU0+DQogICAgPFByb2R1Y3RzPg0KICAgICAgPFByb2R1Y3Q+QXNwb3NlLlRvdGFsIGZvciAuTkVUPC9Qcm9kdWN0Pg0KICAgIDwvUHJvZHVjdHM+DQogICAgPEVkaXRpb25UeXBlPkVudGVycHJpc2U8L0VkaXRpb25UeXBlPg0KICAgIDxTZXJpYWxOdW1iZXI+MjEwZWM4ZTctODFlMS00NTM3LWI0NDYtNjkyZGU0OTgxMjE3PC9TZXJpYWxOdW1iZXI+DQogICAgPFN1YnNjcmlwdGlvbkV4cGlyeT4yMDE5MDUxNzwvU3Vic2NyaXB0aW9uRXhwaXJ5Pg0KICAgIDxMaWNlbnNlVmVyc2lvbj4zLjA8L0xpY2Vuc2VWZXJzaW9uPg0KICAgIDxMaWNlbnNlSW5zdHJ1Y3Rpb25zPmh0dHA6Ly93d3cuYXNwb3NlLmNvbS9jb3Jwb3JhdGUvcHVyY2hhc2UvbGljZW5zZS1pbnN0cnVjdGlvbnMuYXNweDwvTGljZW5zZUluc3RydWN0aW9ucz4NCiAgPC9EYXRhPg0KICA8U2lnbmF0dXJlPmN0SjN5THhTQVBzQlFkMEpjcWY3Q0E1M0Z6TjFZcnZhQTVkU3JUcGRGVy9BZmgwaHlLS3dyeStDMXRqV0lPRUZ5ektZV0grTmduL0hlWFV6TVFKQTBSb293Y3ExMTJuVi9RbnJTU3FEbTZGSlZOc3NINHAvWW1YUmpsN0xCaXh3VjhBYnlXWDhsaFZveW9rN2xJNWs1SzhiYmFLK1Q4VXIrakl3U1pBY21WQT08L1NpZ25hdHVyZT4NCjwvTGljZW5zZT4=";
        public static Stream LStream = (Stream)new MemoryStream(System.Convert.FromBase64String(Key));

        static void 加密()
        {


            new Aspose.Zip.License().SetLicense(LStream);


            var dd = new Aspose.Zip.Saving.ArchiveEntrySettings(new DeflateCompressionSettings(), new AesEcryptionSettings("222222", EncryptionMethod.AES128));

            string zipPath = @"D:\test.zip";
            using (Aspose.Zip.Archive zip = new Aspose.Zip.Archive(dd))
            {

                zip.CreateEntry("test.txt", @"D:\\Test.txt");
                zip.Save(zipPath, new Aspose.Zip.Saving.ArchiveSaveOptions { Encoding = System.Text.Encoding.ASCII });
            }

        }

        static void 解密()
        {
            //new Aspose.Zip.License().SetLicense(LStream);
            var dd = new Aspose.Zip.Saving.ArchiveEntrySettings(new DeflateCompressionSettings(), new AesEcryptionSettings("222222", EncryptionMethod.AES128));

            string zipPath = @"D:\test.zip";
            using (Aspose.Zip.Archive zip = new Aspose.Zip.Archive(zipPath, newEntrySettings: dd))
            {
                zip.Entries[0].Extract(@"D:\Test1.txt");
            }
           
 

        }
    }

}
